#!/usr/bin/bash

BC_CORE_NAME=bc
BC_FC_SRV_NAME=fc_srv

SPATH=`echo $0 | awk -F '/start.sh' '{print $1}'`

BC_CMD="${SPATH}/debug/${BC_CORE_NAME}"
echo $BC_CMD

$BC_CMD &
BC_CORE_PID=$!

$SPATH/build/$BC_FC_SRV_NAME &
BC_FC_SRV_PID=$!

echo $BC_CORE_PID
echo $BC_FC_SRV_PID


if [ -e /usr/bin/waitpid ]
then
  waitpid -c 1 $BC_CORE_PID $BC_FC_SRV_PID
else
  wait -n $BC_CORE_PID $BC_FC_SRV_PID 
fi

if [ "$(ps -p $BC_CORE_PID -o comm --no-headers)" == $BC_CORE_NAME ] 
then
  kill $BC_CORE_PID
fi

if [ "$(ps -p $BC_FC_SRV_PID -o comm --no-headers)" == $BC_FC_SRV_NAME ] 
then
  kill $BC_FC_SRV_PID
fi
